package com.jaks.xpense.data;

import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

import com.jaks.xpense.data.entities.TableEntity;

public abstract class Table {

	protected SQLiteDatabase db;
	private final XpenseDatabase xpense;

	public Table(Context context) throws SQLException {

		xpense = new XpenseDatabase(context);
		db = xpense.getWritableDatabase();
	}

	public void close() {
		xpense.close();
	}

	public abstract long create(TableEntity entity);

	public abstract boolean update(TableEntity entity);

	public abstract boolean delete(long id);

	public abstract Cursor readAll();

	public abstract TableEntity read(long id) throws SQLException;

	protected String where(long id) {
		return TableEntity.Id + "=" + id;
	}
}
